/**
 * 数据库连接测试
 */
(function ({ UID, Type, ConnectionString, User }) {
  // 验证用户
  if (!UID) throw Error("无效会话");
  if (!ConnectionString) throw Error("缺失连接字符串");

  const provider = A.db.provider[Type];
  if (!provider) throw Error("未知的数据库类型");

  const Connection = new provider.DbConnection(ConnectionString);
  try {
    Connection.Open();

    // 验证用户
    if (User) {
      const Cmd = Connection.CreateCommand();
      Cmd.CommandType = A.db.__CommandType.Text;
      Cmd.CommandText = `SELECT 1 FROM B_YH WHERE YHM='admin'`;
      Cmd.ExecuteReader().Close();
    }

    Connection.Close();
    return null;
  } catch (e) {
    return e.message;
  }
});
